package com.campus.admin.controller;

import com.campus.common.core.domain.AjaxResult;
import com.campus.pojos.domain.dto.AdminArticlePageQueryDTO;
import com.campus.pojos.domain.dto.ArticleDto;
import com.campus.pojos.domain.vo.ArticleVo;
import com.campus.result.PageResult;
import com.campus.result.Result;
import com.campus.service.ArticleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 贴子管理相关接口
 */
@RestController(value = "adminArticleController")
@RequestMapping("/system/admin/article")
@Slf4j
public class ArticleController {
    @Autowired
    ArticleService articleService;

    /**
     * 帖子条件查询
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public AjaxResult conditionSearch(@RequestBody AdminArticlePageQueryDTO dto) {
        PageResult pageResult =articleService.conditionSearch(dto);
        System.out.println(dto.getBeginTime());
        return AjaxResult.success("success",pageResult);
    }

    /**
     * 帖子状态修改
     * @param articleId
     * @param status
     */
    @PutMapping("/status")
    public AjaxResult updateStatus(Integer articleId, Integer status)
    {
       articleService.updateStatus(articleId,status);
       return AjaxResult.success();
    }

    /**
     * 编辑帖子
     * @return
     */
    @PutMapping("")
    public AjaxResult edit(@RequestBody ArticleDto articleDto){
        log.info("编辑帖子,{}",articleDto);
        articleService.editArticle(articleDto);
        return AjaxResult.success();
    }
    /**
     * 根据id获取帖子
     * @return
     */
    @GetMapping("/{id}")
    public AjaxResult getArticleById(@PathVariable Long id){
        log.info("根据id查询帖子 id{}",id);
        return articleService.getByArticleIdTwo(id);
    }

    /**
     * 根据id删除帖子
     * @return
     */
    @DeleteMapping("/{id}")
    public AjaxResult deleteById(@PathVariable Long id){
        log.info("根据id删除帖子 id{}",id);
        articleService.removeById(id);
        return AjaxResult.success();
    }

    /**
     * 根据ids删除帖子
     * @return
     */
    @DeleteMapping("/deleteBatch")
    public AjaxResult deleteById(@RequestParam(value = "ids",required = false) List<Long> ids){
        articleService.removeByIds(ids);
        return AjaxResult.success();
    }




}
